//
//  YKGraph.c
//  ProjectM
//
//  Created by gaofeng on 2021/6/20.
//

#include "YKGraph.h"
#include <stdlib.h>

int visited[kMaxVertexNum];

ArcNode *initArcNode(int adj, ArcNode *next){
    ArcNode *arc = malloc(sizeof(ArcNode));
    arc->adjvex = adj;
    arc->next = next;
    return arc;
}

MGraph *initSpaceMGraph(void){
    MGraph *mg = malloc(sizeof(MGraph));
    mg->vexnum = 0;
    mg->arcnum = 0;
    for (int i=0; i<kMaxVertexNum; i++) {
        for (int j=0; j<kMaxVertexNum; j++) {
            mg->Edge[i][j]=0;
        }
    }
    return mg;
}

int AdjacentMGraph(MGraph * G,VertexType x,VertexType y){
    int len = G->vexnum;
    int flga = 0;
    int tx=0,ty = 0;
    for (int i=0; i<len; i++) {
        if (x==G->Vex[i]) {
            flga++;
            tx=i;
        }
        if (y==G->Vex[i]) {
            flga++;
            ty = i;
        }
    }
    if (flga<2) {
        return  1; //   顶点不存在
    }
    EdgeType vlu = G->Edge[tx][ty];
    if (vlu==-1) {
        return 2;
    }else if(vlu==0){
        return  3; // 其他错误
    }else{
        return 0;
    }

}
